package com.snpic.appaw.module.insure.controller.app.orc;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.snpic.appaw.framework.common.pojo.CommonResult;
import com.snpic.appaw.module.insure.controller.app.orc.vo.OcrCommonReqVO;
import com.snpic.appaw.module.insure.controller.app.orc.vo.OcrCommonRespVO;
import com.snpic.appaw.module.insure.controller.app.orc.vo.VehicleLicenseReqVO;
import com.snpic.appaw.module.insure.controller.app.orc.vo.VehicleLicenseRespVO;
import com.snpic.appaw.module.insure.controller.app.vehicleInformation.vo.AppVehicleInformationSaveReqVO;
import com.snpic.appaw.module.insure.service.orc.ClientOCRService;
import com.snpic.appaw.module.third.api.deepOCR.DeepOCRApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author JiJun
 * @date 2025/9/11 11:14
 * @修改时间 2025/9/11 11:14
 * @description
 */
@Tag(name = "C端 - ORC影像识别")
@RestController
@RequestMapping("/insure/ocr")
@RequiredArgsConstructor
@Slf4j
@Validated
public class ClientOCRController {
	@Resource
	private DeepOCRApi deepOCRApi;

	@Resource
	private ClientOCRService clientOCRService;

	/**
	 * 行驶证(正页识别)
	 *
	 * @param reqVO
	 * @return
	 */
	@PostMapping("/vehicle_license")
	@Operation(summary = "行驶证(正页识别)")
	public CommonResult<VehicleLicenseRespVO> vehicleLicense(@RequestBody @Validated VehicleLicenseReqVO reqVO) {
		VehicleLicenseRespVO respVO = clientOCRService.vehicleLicense(reqVO);
		return CommonResult.success(respVO);
	}

	@PostMapping(value = "/ocrCommonHandle", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	@Operation(summary = "ORC通用识别,根据文件类型区分")

	public CommonResult<OcrCommonRespVO> ocrCommonHandle(
		@RequestPart(value = "file") @Schema(description = "被ORC的文件") MultipartFile file,
		@RequestParam("data") String jsonData
	) throws IOException {

		// 将 JSON 字符串反序列化为对象
		OcrCommonReqVO reqVO = new ObjectMapper().readValue(jsonData, OcrCommonReqVO.class);

		OcrCommonRespVO ocrCommonRespVO = clientOCRService.ocrCommonHandle(file,reqVO);

		return  CommonResult.success(ocrCommonRespVO);

	}



}
